<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //构造函数
        function Person(name) {
            this.name = name;
        }
        //为构造函数的原型对象添加 继承方法
        Person.prototype.extend = function (obj) {  //extend 合并属性
            //将传入的obj对象 的属性和方法继承给 实例对象
            for (var k in obj) {
                this[k] = obj[k];
            }
        }
        //实例化对象 
        var p1 = new Person('jack');

        var p2 = { age: 18, sex: '男' }

        //p1想继承p2的属性和方法
        p1.extend(p2);
        console.log(p1);

    </script>
</body>

</html>